<?php

require_once 'Base.php';

class Apply extends Base {
    public function send(){
        if($_POST){
            $requestParams=$_POST;
            //对敏感信息加密
            $requestParams['id_card_name']=$this->publicKeyEncrypt($requestParams['id_card_name']);
            $requestParams['id_card_number']=$this->publicKeyEncrypt($requestParams['id_card_number']);
            $requestParams['account_name']=$this->publicKeyEncrypt($requestParams['account_name']);
            $requestParams['account_number']=$this->publicKeyEncrypt($requestParams['account_number']);
            $requestParams['contact']=$this->publicKeyEncrypt($requestParams['contact']);
            $requestParams['contact_phone']=$this->publicKeyEncrypt($requestParams['contact_phone']);

            $requestParams['sign']=$this->generateSign($requestParams);
            $url="https://api.mch.weixin.qq.com/applyment/micro/submit";

            $response=$this->curlRequest($url,$this->arrayToXml($requestParams),[],true);

            if($response['return_code'] != 'SUCCESS'){
                exit($response['return_msg']);
            }
            if($response['result_code'] != 'SUCCESS'){
                exit($response['err_code_des']);
            }
            $this->checkSign($response);

            //将结果进行储存
            file_put_contents($this->applyDataPath,json_encode($response),FILE_APPEND);
            echo '商户申请单号为：'.$response['applyment_id'];
        }
    }
}

return (new Apply())->send();